﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.CodeDom.Compiler;


using Microsoft.VisualStudio.TextTemplating.CommandLine;

using Newtonsoft.Json.Linq;
namespace T4Ui
{
    public partial class testFrm : Form
    {
        public testFrm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void btnTestTextTransform_Click(object sender, EventArgs e)
        {
            try
            {
                string[] cols = { txtparaT4.Text };
                StringBuilder mess = new StringBuilder();
                TextTransform.MainText(cols, mess);
                MessageBox.Show(mess.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnJsonobjectTest_Click(object sender, EventArgs e)
        {
            try
            {
                JObject main = new JObject();
                JArray arr = new JArray();
                arr.Add("tblACF_UpdateDetails1");
                arr.Add("tblSCR_SummaryDetail");
                arr.Add("tblSCR_SummaryMain");
                arr.Add("tblKDF_StorageDesc2");
                main.Add("tblIst",arr);

                string[] cols = { txtJsonT4Tt.Text };
                StringBuilder mess = new StringBuilder();
                //host.Parameters.Add("!!Namespace!test.gen");
                //host.Parameters.Add(@"!!ConnStr!Password=password;Persist Security Info=True;User ID=sa;Initial Catalog=TAMIC4DB;Data Source=192.168.40.128\SQLEXPRESS");
                string[] paras = { "!!tblName!" + main.ToString(), "!!Namespace!test.gen",@"!!ConnStr!Password=password;Persist Security Info=True;User ID=sa;Initial Catalog=TAMIC4DB;Data Source=192.168.40.128\SQLEXPRESS" };
                string loc = main.ToString();
                JObject obj1 = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(loc);
              
                TextTransform.CallT4(cols, paras, mess);
                MessageBox.Show(mess.ToString());
                //MessageBox.Show(list[0].ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnClassTT_Click(object sender, EventArgs e)
        {
            try
            {
                string[] cols = { txtTtClass.Text };
                TextTransform.Main(cols); ;
                //MessageBox.Show(mess.ToString());
                //MessageBox.Show(list[0].ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnUIGenerator_Click(object sender, EventArgs e)
        {
            try
            {
                GeneratorCode gen = new GeneratorCode();
                gen.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
